#define BIN1  7
#define AIN1  4

#define AIN2  5
#define BIN2  6

#define SLEEP 12  // low to sleep

char c = 's';

void  setup()
{
	Serial.begin(115200);

	pinMode(AIN1, OUTPUT);
	pinMode(AIN1, OUTPUT);
	pinMode(BIN1, OUTPUT);
	pinMode(BIN1, OUTPUT);
	pinMode(SLEEP, OUTPUT);

	digitalWrite(SLEEP,HIGH);
	digitalWrite(AIN1,LOW);
	digitalWrite(AIN2,LOW);
	digitalWrite(BIN1,LOW);
	digitalWrite(BIN2,LOW);
}
void  loop()
{
	if(Serial.available())
	{
	   c = Serial.read();
	}
	if(c == 'f')
	{
		forward();
	}
	if(c == 'b')
	{
	    backward();
	}
	if(c == 's')
	{
	    stop();
	}
	if(c == 'l')
	{
	    turnLeft();
	}
	if(c == 'r')
	{
	 	turnRight();   
	}
	else 
	c = 0;
}
void forward()
{
	digitalWrite(AIN1,HIGH);
	digitalWrite(AIN2,LOW);
	digitalWrite(BIN1,LOW);
	digitalWrite(BIN2,HIGH);
}
void backward()
{
	digitalWrite(BIN1,HIGH);
	digitalWrite(BIN2,LOW);
	digitalWrite(AIN1,LOW);
	digitalWrite(AIN2,HIGH);
}
void stop()
{
	digitalWrite(AIN1,LOW);
	digitalWrite(AIN2,LOW);
	digitalWrite(BIN1,LOW);
	digitalWrite(BIN2,LOW);
}
void turnLeft()
{
	digitalWrite(AIN1,HIGH);
	digitalWrite(AIN2,LOW);
	digitalWrite(BIN1,HIGH);
	digitalWrite(BIN2,LOW);
}
void turnRight()
{
	digitalWrite(AIN1,LOW);
	digitalWrite(AIN2,HIGH);
	digitalWrite(BIN1,LOW);
	digitalWrite(BIN2,HIGH);
}